#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

int check(long t)
{
    char str[101];
    int len, i;

    sprintf(str, "%ld", t);
    len = strlen(str);
    for (i = 0; i < len / 2; i++) {
        if (str[i] != str[len-1-i]) {
            return 0;
        }
    }
    
    return 1;
}

int main (int argc, char const* argv[])
{
    int n, cnt, ans, a, b, i;
    long start, end, test;

    scanf("%d", &n);
    cnt = 1;

    while (cnt <= n) {
        scanf("%d %d", &a, &b);

        start = (long)sqrt(a);
        end = (long)sqrt(b);

        ans = 0;
        for (i = start; i <= end; i++) {
            if (i * i < a) continue;
            test = i * i;
            ans += check(i) ? check(test) : 0;
        }

        printf("Case #%d: %d\n", cnt, ans);

        cnt++;
    }

    return 0;
}
